<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="用户密码" prop="password">-->
<!--        <el-input-->
<!--          v-model="queryParams.password"-->
<!--          placeholder="请输入用户密码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户手机号，可不绑定" prop="phone">-->
<!--        <el-input-->
<!--          v-model="queryParams.phone"-->
<!--          placeholder="请输入用户手机号，可不绑定"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户起始体重" prop="createWeight">-->
<!--        <el-input-->
<!--          v-model="queryParams.createWeight"-->
<!--          placeholder="请输入用户起始体重"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户目标体重" prop="goalWeight">-->
<!--        <el-input-->
<!--          v-model="queryParams.goalWeight"-->
<!--          placeholder="请输入用户目标体重"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户最新体重" prop="newWeight">-->
<!--        <el-input-->
<!--          v-model="queryParams.newWeight"-->
<!--          placeholder="请输入用户最新体重"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="身高-->
<!--" prop="height">-->
<!--        <el-input-->
<!--          v-model="queryParams.height"-->
<!--          placeholder="请输入身高-->
<!--"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="BMI值" prop="bmi">-->
<!--        <el-input-->
<!--          v-model="queryParams.bmi"-->
<!--          placeholder="请输入BMI值"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="获赞总数" prop="supportCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.supportCount"-->
<!--          placeholder="请输入获赞总数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="关注总数" prop="friendCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.friendCount"-->
<!--          placeholder="请输入关注总数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发帖数" prop="postCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.postCount"-->
<!--          placeholder="请输入发帖数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="累计签到" prop="signDay">-->
<!--        <el-input-->
<!--          v-model="queryParams.signDay"-->
<!--          placeholder="请输入累计签到"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['M:jianfeiuser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['M:jianfeiuser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['M:jianfeiuser:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['M:jianfeiuser:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jianfeiuserList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="用户密码" align="center" prop="password" />
      <el-table-column label="用户手机号" align="center" prop="phone" />
      <el-table-column label="头像" align="center" prop="userImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.userImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="用户起始体重" align="center" prop="createWeight" />
      <el-table-column label="用户目标体重" align="center" prop="goalWeight" />
      <el-table-column label="用户最新体重" align="center" prop="newWeight" />
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="BMI值" align="center" prop="bmi" />
      <el-table-column label="获赞总数" align="center" prop="supportCount" />
      <el-table-column label="关注总数" align="center" prop="friendCount" />
      <el-table-column label="发帖数" align="center" prop="postCount" />
      <el-table-column label="累计签到" align="center" prop="signDay" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['M:jianfeiuser:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['M:jianfeiuser:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改减肥用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="用户密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入用户密码" />
        </el-form-item>
        <el-form-item label="用户手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入用户手机号，可不绑定" />
        </el-form-item>
        <el-form-item label="头像" prop="userImage">
          <image-upload v-model="form.userImage"/>
        </el-form-item>
        <el-form-item label="用户起始体重" prop="createWeight">
          <el-input v-model="form.createWeight" placeholder="请输入用户起始体重" />
        </el-form-item>
        <el-form-item label="用户目标体重" prop="goalWeight">
          <el-input v-model="form.goalWeight" placeholder="请输入用户目标体重" />
        </el-form-item>
        <el-form-item label="用户最新体重" prop="newWeight">
          <el-input v-model="form.newWeight" placeholder="请输入用户最新体重" />
        </el-form-item>
        <el-form-item label="身高
" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高
" />
        </el-form-item>
        <el-form-item label="BMI值" prop="bmi">
          <el-input v-model="form.bmi" placeholder="请输入BMI值" />
        </el-form-item>
        <el-form-item label="获赞总数" prop="supportCount">
          <el-input v-model="form.supportCount" placeholder="请输入获赞总数" />
        </el-form-item>
        <el-form-item label="关注总数" prop="friendCount">
          <el-input v-model="form.friendCount" placeholder="请输入关注总数" />
        </el-form-item>
        <el-form-item label="发帖数" prop="postCount">
          <el-input v-model="form.postCount" placeholder="请输入发帖数" />
        </el-form-item>
        <el-form-item label="累计签到" prop="signDay">
          <el-input v-model="form.signDay" placeholder="请输入累计签到" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJianfeiuser, getJianfeiuser, delJianfeiuser, addJianfeiuser, updateJianfeiuser } from "@/api/M/jianfeiuser"

export default {
  name: "Jianfeiuser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 减肥用户表格数据
      jianfeiuserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName: null,
        password: null,
        phone: null,
        userImage: null,
        createWeight: null,
        goalWeight: null,
        newWeight: null,
        height: null,
        bmi: null,
        supportCount: null,
        friendCount: null,
        postCount: null,
        signDay: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        nickName: [
          { required: true, message: "用户昵称不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "用户密码不能为空", trigger: "blur" }
        ],
        userImage: [
          { required: true, message: "头像，得有默认值不能为空", trigger: "blur" }
        ],
        createWeight: [
          { required: true, message: "用户起始体重不能为空", trigger: "blur" }
        ],
        goalWeight: [
          { required: true, message: "用户目标体重不能为空", trigger: "blur" }
        ],
        newWeight: [
          { required: true, message: "用户最新体重不能为空", trigger: "blur" }
        ],
        bmi: [
          { required: true, message: "BMI值不能为空", trigger: "blur" }
        ],
        supportCount: [
          { required: true, message: "获赞总数不能为空", trigger: "blur" }
        ],
        friendCount: [
          { required: true, message: "关注总数不能为空", trigger: "blur" }
        ],
        postCount: [
          { required: true, message: "发帖数不能为空", trigger: "blur" }
        ],
        signDay: [
          { required: true, message: "累计签到不能为空", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询减肥用户列表 */
    getList() {
      this.loading = true
      listJianfeiuser(this.queryParams).then(response => {
        this.jianfeiuserList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nickName: null,
        password: null,
        phone: null,
        userImage: null,
        createWeight: null,
        goalWeight: null,
        newWeight: null,
        height: null,
        bmi: null,
        createTime: null,
        updateTime: null,
        supportCount: null,
        friendCount: null,
        postCount: null,
        signDay: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加减肥用户"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getJianfeiuser(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改减肥用户"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateJianfeiuser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addJianfeiuser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除减肥用户编号为"' + ids + '"的数据项？').then(function() {
        return delJianfeiuser(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('M/jianfeiuser/export', {
        ...this.queryParams
      }, `jianfeiuser_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
